package com.dex4d.ui.main.activity;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;

import com.dex4d.R;
import com.dex4d.core.AppBaseActivity;
import com.dex4d.model.User;
import com.dex4d.ui.demo.HomeActivity;
import com.dex4d.ui.wallet.activity.PreLoginActivity;
import com.framework.util.StringUtil;

import java.lang.ref.WeakReference;

/**
 * Created by chengyuchun on 2018/10/17.
 *
 */

public class WelcomeActivity extends AppBaseActivity {
    private Handler mHandler = new  SecureHandler(this);

    static class SecureHandler extends Handler {
        WeakReference<Activity> mActivityReference;

        SecureHandler(Activity activity) {
            mActivityReference = new WeakReference<Activity>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            final Activity activity = mActivityReference.get();
            if(!StringUtil.isEmpty(User.getInstance().getKeystore())
                    &&User.getInstance().isBackup()){
                HomeActivity.start(activity);
            }else {
                PreLoginActivity.start(activity);
            }
            activity.finish();
        }

        public Activity getActivity(){
            if(mActivityReference!=null){
                return mActivityReference.get();
            }else {
                return null;
            }
        }
    }



    @Override
    public void initVariables() {

    }

    @Override
    public void loadData() {
        mHandler.sendEmptyMessageDelayed(0, 1000);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mHandler.removeMessages(0);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_welcome;
    }
}
